
import yaml
import sys
import os
import config_keepalived

configYml = open(r'../config.yml')
config = yaml.safe_load(configYml)
isIngressProviderEnable = config['ingress-provider']['enable']
print('ingress provider enable: ' +
      str(isIngressProviderEnable))
if not isIngressProviderEnable:
    print('this node ingress provider not enable')
    sys.exit(0)

isMasterHighAvailabilityEnable = config['master-high-availability']['enable']
if isMasterHighAvailabilityEnable:
    print('currently, master high availability and ingres high availability are not supported at the same time, because a node keepalived can not support two vip at the same time currently')
    sys.exit(0)

config_keepalived.prepareKeepalivedConfigFile()
os.system('./keepalived-config.sh')

nodeName = config['node-name']
os.system('kubectl label node ' + nodeName + ' ingresscontroller=traefik --overwrite')

os.system('../util/install-helm.sh')
os.chdir('./traefik')
os.system('./deploy.sh')